Context Free Language 2

CFG 2

Methods for Transforming Grammars

  • 定理6.1

    alt text

    • 代換 variable
  • 有效的代換規則

    alt text

NULLable Production

  • 代換 null

    alt text

  • Example

    alt text

    • 把null production代換掉

      alt text

    • 多個production的例子

Unit production

  • Production 兩端都只有一個variable

    alt text
    alt text

    • 直接移除

      alt text

    • 畫出關係圖
      • P1: B產生自S
      • P2: A產生自B
      • P3: B產生自A

        alt text

      • 根據關係圖 拓展

Useless Production

  • 不終結的Production

    alt text

  • 不抵達的Production

    alt text

  • 如何移除

    alt text
    alt text
    alt text
    alt text
    alt text

移除順序

  • 順序

    alt text

Two Important Normal Form

  • CNF

    alt text

    • Example

      alt text

    • 如何轉換成CNF

      alt text
      alt text

      • Terminal 換成 Variable

        alt text

      • 兩個Variable一組 由一個新的Variable生成…
    • 不包含 null的production 都可以換成等價的CNF

      alt text

    • 作法

      alt text

    • CNF 很適合Parsing

      alt text

  • GNF

    alt text

    • Example

      alt text

    • CFG 可以轉換成 GNF

      alt text

    • GNF 適合Parsing 但很難找出來

      alt text

A Membership Algorithm for CFGs*

  • 如何確定一個字串屬於當前的CFG

    alt text

  • CYK

    alt text

    • Example

      alt text
      alt text

      • 從每個index 向後推算

        alt text
        alt text
        alt text
        alt text


Context Free Language 2
https://z-hwa.github.io/webHome/[object Object]/Theory of Computation/Context-Free-Language-2/
作者
crown tako
發布於
2025年1月6日
許可協議